import os
from typing import List
from pydantic_settings import BaseSettings

class Settings(BaseSettings):
    """应用配置管理"""

    # 应用基本信息
    app_name: str = "教学数据分析与预测API"
    app_version: str = "1.0.0"
    debug: bool = False

    # 服务器配置
    host: str = "0.0.0.0"
    port: int = 8000
    reload: bool = True

    # CORS配置
    cors_origins: List[str] = ["http://localhost:8080", "http://127.0.0.1:8080"]

    # 数据文件路径
    data_dir: str = "./data"

    # 日志配置
    log_level: str = "INFO"
    log_file: str = "./logs/app.log"

    # 模型配置
    model_random_state: int = 42
    test_size: float = 0.3

    # API文档配置
    docs_url: str = "/docs"
    redoc_url: str = "/redoc"

    class Config:
        env_file = ".env"
        env_file_encoding = "utf-8"
        case_sensitive = False

# 创建全局配置实例
settings = Settings()

def get_data_file_path(filename: str) -> str:
    """获取数据文件的完整路径"""
    current_dir = os.path.dirname(os.path.abspath(__file__))
    return os.path.join(current_dir, settings.data_dir, filename)